package qianting.news.wemedia.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qianting.news.apis.models.wemedia.dtos.NewsAuthDto;
import qianting.news.apis.models.wemedia.dtos.WmNewsDto;
import qianting.news.apis.models.wemedia.dtos.WmNewsPageReqDto;
import qianting.news.common.constant.WemediaConstants;
import qianting.news.common.entity.State;
import qianting.news.wemedia.service.WmNewsService;

@Api(tags = "文章管理")
@RestController
@RequestMapping("/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    //列出当前用户的文章
    @ApiOperation(value = "列出当前用户的文章")
    @PostMapping("list")
    public State findAll(@RequestBody WmNewsPageReqDto dto){
        return  wmNewsService.findAll(dto);
    }

    //保存或修改文章
    @ApiOperation(value = "保存或修改文章")
    @PostMapping("submit")
    public State submitNews(@RequestBody WmNewsDto dto){
        return  wmNewsService.submitNews(dto);
    }

    //文章的上下架->kafka消息通知
    @ApiOperation(value = "文章的上下架->kafka消息通知")
    @PostMapping("down_or_up")
    public State downOrUp(@RequestBody WmNewsDto dto){
        return wmNewsService.downOrUp(dto);
    }

    //根据id查询文章详情
    @ApiOperation(value = "根据id查询文章详情")
    @GetMapping("/one/{id}")
    public State findOne(@PathVariable("id") Integer id){
        return wmNewsService.findOne(id);
    }

    //根据id查询文章详情-->携带用户信息
    @ApiOperation(value = "根据id查询文章详情-->携带用户信息")
    @GetMapping("/one_vo/{id}")
    public State findWmNewsVo(@PathVariable("id") Integer id){
        return wmNewsService.findWmNewsVo(id);
    }

    //根据文章的标题或者状态查询或者审核失败的原因查询文章列表
    @ApiOperation(value = "根据文章的标题或者状态查询或者审核失败的原因查询文章列表")
    @PostMapping("/list_vo")
    public State findList(@RequestBody NewsAuthDto dto){
        return wmNewsService.findList(dto);
    }

    //文章审核通过
    @ApiOperation(value = "文章审核通过")
    @PostMapping("/auth_pass")
    public State authPass(@RequestBody NewsAuthDto dto){
        return wmNewsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_PASS,dto);
    }

    //文章审核不通过
    @ApiOperation(value = "文章审核不通过")
    @PostMapping("/auth_fail")
    public State authFail(@RequestBody NewsAuthDto dto){
        return wmNewsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_FAIL,dto);
    }

}